//设置
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var credentialController = (function (_super) {
    __extends(credentialController, _super);
    function credentialController($scope, credentialService, $ngBootbox) {
        var _this = this;
        _super.call(this, $scope);
        this.credentialService = credentialService;
        this.$ngBootbox = $ngBootbox;
        /**
         * 生成AppKey,AppSecrect
         */
        this.generateRandomCredential = function () {
            _this.$scope.appKey = _this.makeId(10);
            _this.$scope.appSecrect = _this.makeId(15);
        };
        /**
         * 添加
         */
        this.showDialogAddDate = function () {
            _this.$ngBootbox.confirm("确定保存该数据吗？").then(function (e) {
                _this.credentialService.add(_this.$scope.appKey, _this.$scope.appSecrect).then(function (result) {
                    _this.query();
                    $('#myModal').modal('hide');
                });
            });
        };
        /**
         * 删除
         */
        this.showDialogDeleteDate = function (id) {
            _this.$ngBootbox.confirm("是否删除该数据？").then(function (e) {
                _this.credentialService.delete(id).then(function (result) {
                    _this.query();
                });
            });
        };
        /**
         * 刷新
         */
        this.refresh = function () {
            _this.query();
        };
        this.init();
    }
    credentialController.prototype.init = function () {
        var _this = this;
        _super.prototype.init.call(this);
        this.$scope.appKey = '';
        this.$scope.appSecrect = '';
        this.$scope.addDate = this.showDialogAddDate;
        this.$scope.deleteDate = this.showDialogDeleteDate;
        this.$scope.refresh = this.refresh;
        this.$scope.generateRandomCredential = this.generateRandomCredential;
        this.$scope.gridOptions = {
            enableSorting: false,
            useExternalPagination: true,
            //useExternalSorting: true,
            enableColumnResizing: true,
            paginationPageSizes: [10, 20, 30],
            columnDefs: [
                { name: "序号", field: "index", enableColumnMenu: false },
                { name: "AppKey", field: "appKey", enableColumnMenu: false },
                { name: "AppSecrect", field: "appSecrect", enableColumnMenu: false },
                {
                    name: "操作",
                    cellFilter: "checkmark",
                    cellTemplate: '<a class="primary fa fa-trash-o text-danger" title="删除" ng-click="grid.appScope.deleteDate(row.entity.id)"></a>',
                    enableColumnMenu: false
                }
            ],
            onRegisterApi: function (gridApi) {
                _this.gridApi = gridApi;
                gridApi.pagination.on.paginationChanged(_this.$scope, _this.paginationChanged);
            }
        };
        this.query();
    };
    credentialController.prototype.loadData = function (queryTerms, skip, count) {
        var _this = this;
        this.credentialService.getList(skip, count).then(function (result) {
            _this.$scope.gridOptions.totalItems = result.data.total;
            _this.$scope.gridOptions.data = result.data.list;
            if (skip == 0) {
                _this.$scope.gridOptions.paginationCurrentPage = 1;
            }
            _this.$scope.querying = false;
        }, function (error) {
            _this.$scope.querying = false;
        });
    };
    /**
     *生成id数据
     */
    credentialController.prototype.makeId = function (count) {
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for (var i = 0; i < count; i++) {
            text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    };
    return credentialController;
}(ListController));
app.controller('credentialController', ['$scope', 'credentialService', '$ngBootbox', credentialController]);
